//长度最小的子数组
//测试链接 https://leetcode.cn/problems/minimum-size-subarray-sum/description/
public class MinSubArrayLen {
    public int minSubArrayLen(int target, int[] nums) {
        int sum = 0, n = nums.length;
        int len = n+1;
        for(int left = 0, right = 0; right < n; right++){
            sum += nums[right];
            while(sum >= target){
                len = Math.min(len, right-left+1);
                sum -= nums[left];
                left++;
            }
        }

        return len == n+1 ? 0 : len;
    }
}
